from app import db

from app.models.base_model import BaseModel
from app.common.enums import AuthPermissionType


class AuthPermission(BaseModel):
    __tablename__ = 'auth_permission'
    __table_args__ = ({'comment': '认证权限表'})
    id = db.Column(db.Integer, primary_key=True, comment="权限ID")
    p_code = db.Column(db.String(255), unique=True, nullable=False, comment="权限标识")
    p_name = db.Column(db.String(255), nullable=False, comment="权限名称")
    p_expression = db.Column(db.String(255), nullable=False, comment="权限表达式")
    p_type = db.Column(
        db.Enum(AuthPermissionType),
        server_default=AuthPermissionType.action.name,
        nullable=False,
        comment="权限类型"
    )
    is_enabled = db.Column(db.Boolean, default=True, nullable=False, comment="启用")
    description = db.Column(db.String(255), nullable=True, comment="权限备注")

    def __repr__(self) -> str:
        return "<AuthPermission %s>" % self.to_json()
